package com.gears_software.sxdc.dccx.ui.activity;

import android.content.Context;
import android.support.v4.app.Fragment;
import android.support.v4.content.ContextCompat;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.TextView;

import com.gears_software.sxdc.dccx.R;
import com.gears_software.sxdc.dccx.application.DCCXApplication;
import com.gears_software.sxdc.dccx.data.adapter.FragmentAdapter;
import com.gears_software.sxdc.dccx.ui.fragment.CarPoolFragment_;
import com.gears_software.sxdc.dccx.ui.fragment.NoUseVouchersFragment;
import com.gears_software.sxdc.dccx.ui.fragment.NoUseVouchersFragment_;
import com.gears_software.sxdc.dccx.ui.fragment.SpecialCarFragment_;
import com.gears_software.sxdc.dccx.ui.fragment.UseVouchersFragment;
import com.gears_software.sxdc.dccx.ui.fragment.UseVouchersFragment_;
import com.gigamole.navigationtabstrip.NavigationTabStrip;

import org.androidannotations.annotations.AfterViews;
import org.androidannotations.annotations.App;
import org.androidannotations.annotations.Click;
import org.androidannotations.annotations.EActivity;
import org.androidannotations.annotations.ViewById;

import java.util.ArrayList;
import java.util.List;

import qiu.niorgai.StatusBarCompat;

/**
 * Created by chezhenzhen on 2017/11/22.
 */

@EActivity(R.layout.activity_vouchers)
public class VouchersActivity extends AppCompatActivity {

    @App
    DCCXApplication app;
    @ViewById
    TextView back_icon;
    @ViewById
    TextView right_icon;
    @ViewById
    TextView actionbar_title;
    @ViewById
    NavigationTabStrip navigationTabStrip;
    @ViewById
    ViewPager viewpager;
    NoUseVouchersFragment noUse;
    UseVouchersFragment use;
    String[] titles = {"末使用", "已使用"};
    FragmentAdapter adapter;
    List<Fragment> pages = new ArrayList<Fragment>();
    Context context;


    @AfterViews
    void created() {
        StatusBarCompat.setStatusBarColor(this, ContextCompat.getColor(this, R.color.colorActionbar));
        initIconFont();
        initViewPager();
        initNavTabStrip();
    }

    private void initIconFont() {
        actionbar_title.setText("代金劵");
        back_icon.setText(R.string.back_icon);
        back_icon.setTypeface(app.iconfont);
        right_icon.setVisibility(View.GONE);
    }

    void initViewPager() {
        noUse = new NoUseVouchersFragment_();
        use = new UseVouchersFragment_();
        pages.add(noUse);
        pages.add(use);
        adapter = new FragmentAdapter(getSupportFragmentManager(), pages, titles);
        viewpager.setAdapter(adapter);
        viewpager.setCurrentItem(0);
    }

    void initNavTabStrip() {
        navigationTabStrip.setTitles(titles);
        navigationTabStrip.setTitleSize(getResources().getDimensionPixelSize(R.dimen.normal_font_size));
        navigationTabStrip.setStripColor(ContextCompat.getColor(this,R.color.colorActionbar));
        navigationTabStrip.setStripWeight(2);
        navigationTabStrip.setStripFactor(2);
        navigationTabStrip.setStripGravity(NavigationTabStrip.StripGravity.BOTTOM);
        navigationTabStrip.setStripType(NavigationTabStrip.StripType.LINE);
//        navigationTabStrip.setTypeface("fonts/typeface.ttf");
        navigationTabStrip.setCornersRadius(3);
        navigationTabStrip.setAnimationDuration(300);
        navigationTabStrip.setInactiveColor(ContextCompat.getColor(this, R.color.colorTabFont));
        navigationTabStrip.setActiveColor(ContextCompat.getColor(this, R.color.colorActionbar));
        navigationTabStrip.setViewPager(viewpager, 0);
        app.index = 0;
        navigationTabStrip.setOnTabStripSelectedIndexListener(new NavigationTabStrip.OnTabStripSelectedIndexListener() {
            @Override
            public void onStartTabSelected(String title, int index) {

            }

            @Override
            public void onEndTabSelected(String title, int index) {

            }
        });
    }

    @Click
    void back_icon() {
        this.finish();
    }
}
